package cn.edu.lingnan.service;

import cn.edu.lingnan.dao.*;
import cn.edu.lingnan.pojo.Position;
import cn.edu.lingnan.pojo.Student;

import java.util.ArrayList;
import java.util.List;

public class StudentServiceMysqlImpl implements StudentService {
    StudentDao studentDao = new StudentDaoMysqlImpl();
    ClubDao clubDao=new ClubDaoMysqlImpl();
    PositionDao memberDao=new PositionDaoMysqlImpl();
    @Override
    public boolean newStudent(Student _student) {
        return studentDao.newStudent(_student);
    }

    @Override
    public Student findStudentBySidAndPassword(String _sid, String _password) {
        return studentDao.findStudentBySidAndPassword(_sid, _password);
    }

    @Override
    public List<Student> findStudnetAll() {
        return studentDao.findStudnetAll();
    }

    @Override
    public Student findStudentBySid(String _sid) {
        return studentDao.findStudentBySid(_sid);
    }

    @Override
    public List<Student> findStudentBySname(String _sname) {
        return studentDao.findStudentBySname(_sname);
    }

    @Override
    public boolean deleteStudentBySid(String _sid) {
        boolean flag=false;
        List<Position> Members=new ArrayList<>();
        Members=memberDao.findPositionBySid(_sid);
        for (Position member : Members) {
            memberDao.deletePositionBySidAndCid(_sid,"");
        }
        return studentDao.deleteStudentBySid(_sid);
    }

    @Override
    public boolean updateNameBySid(String _sid, String _sname) {
        return studentDao.updateNameBySid(_sid,_sname);
    }

    @Override
    public boolean updatePasswordBySid(String _sid, String _password) {
        return studentDao.updatePasswordBySid(_sid,_password);
    }

    @Override
    public boolean updateSrightBySid(String _sid, String _sright) {
        return studentDao.updateSrightBySid(_sid,_sright);
    }

    @Override
    public boolean updateSflagBySid(String _sid, String _sflag) {
        return studentDao.updateSflagBySid(_sid,_sflag);
    }

    @Override
    public boolean updateStudent(Student _student) {
        return studentDao.updateStudent(_student);
    }

}
